<?php

namespace wechat\bun;

use wechat\Wx;

class User extends Wx{

    public function remarks($post){

        $token = $this->getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/tags/create?access_token='.$token;
        $data = $this->curl($url,$post);
        echo $data;
//        $data = json_decode($data,true);
//        if (isset($data['tag'])){
//
//            return true;
//
//        }else{
//
//            return false;
//        }
    }

//    获得已经分类的标签
    public function getlabel(){
//        echo 123;
        $token = $this->getAccessToken();
//        echo $token;
        $url = 'https://api.weixin.qq.com/cgi-bin/tags/get?access_token='.$token;

        $data = $this->curl($url);
//        echo $data;
        $data = json_decode($data,true);
//        print_r($data);
        if ($data['tags']){
            return true;
        }else{
            return false;
        }
    }


//    设置用户备注名
    public function setremark($post){
        $token = $this->getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token='.$token;
        $data = $this->curl($url,$post);
        echo $data;
    }

//    获得用户的基本信息
    public function getuserinfo(){
        $token = $this->getAccessToken();
        $openid = 'oZ6Ga1ZHGw_lR6eT2sXjwF_bNUuI';
        $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$token.'&openid='.$openid.'&lang=zh_CN';
        $data = $this->curl($url);
        echo $data;
    }

//    第一种方式批量获取用户信息
    public function moreuserinfo($post){
        $token = $this->getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token='.$token;
        $data = $this->curl($url,$post);
        echo $data;
    }

//    第二种方式批量获取用户信息
    public function more_2_userinfo($post,$lang="zh_CN"){
//        print_r($post);
        $token = $this->getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token='.$token;
        $users = [];
        foreach ($post as $v){
            $users['user_list'][]=[
              "openid"=>$v,
                'lang'=>$lang
            ];
        }
//        echo "<pre>";
//        print_r($users);
        $users = json_encode($users);
//        echo $users;
        $data = $this->curl($url,$users);
//        echo $data;
        $data = json_decode($data,true);
        if (isset($data['errcode'])){
            return false;
        }else{
            return $data;
        }
    }

//    获取用户列表
    public function userlist(){

        $token = $this->getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token='.$token;
        $data = $this->curl($url);
        echo $data;
    }
}


?>
